#include<stdio.h>
#include "bib.h"


void jouer(sudoku g, int charge)
{
     int i,j,k,nbr=0,li,li2,co2,co,val,s=0,li3,co3;
     char nom[30],value[2];
     for(i=0;i<9;i++)
     {
                     for(j=0;j<9;j++)
                     {
                                     if(g.grille[i][j]==0)
                                     s=s+1;
                     }
     }
     do
     {
          if(charge == 1)
          afficher_grille_chargee(g);
          else
          afficher_grille(g);
          printf("Taper la valeur de la ligne de la case : ");
          scanf("%d",&li);
          switch(li)
          {
                      case 0:break;
                      case 1:break;
                      case 2:break;
                      case 3:break;
                      case 4:break;
                      case 5:break;
                      case 6:break;
                      case 7:break;
                      case 8:break;

                      default:printf("Vous faites une erreur de saisie\n\n");
             }
             printf("Taper la valeur de la colonne de la case : ");
             scanf("%d",&co);
             switch(co)
             {
                      case 0:break;
                      case 1:break;
                      case 2:break;
                      case 3:break;
                      case 4:break;
                      case 5:break;
                      case 6:break;
                      case 7:break;
                      case 8:break;

                       default:printf("Vous faites une erreur de saisie\n\n");
             }
             if(charge==1)
             {
                 if(g.grille[li][co]==48)
                 {
                    printf("taper la valeur :");
                    scanf("%d",&val);
                    switch(val)
                    {
                        case 1:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 2:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 3:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 4:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 5:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 6:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 7:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 8:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;
                        case 9:g.grille[li][co]=val+48;
                               nbr++;
                               g.score=g.score+10;
                               break;

                       default:printf("Vous faites une erreur de saisie\n\n");
                       system("CLS");
                    }
                    system("CLS");
                 }
                 else
                 {
                     printf("Erreur : cette case est deja occupee.\n");
                 }

             }
             else
             {
                 if(g.grille[li][co]==0)
                 {
                    printf("taper la valeur :");
                    scanf("%d",&val);
                    switch(val)
                    {

                      case 1:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 2:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 3:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 4:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 5:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 6:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 7:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 8:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;
                      case 9:g.grille[li][co]=val;
                             nbr++;
                             g.score=g.score+10;
                             system("CLS");
                             break;

                      default:printf("Vous faites une erreur de saisie\n\n");
                      system("CLS");
                    }
                 }
                 else
                 {
                     printf("Erreur : cette case est dejaoccupee.\n");
                 }
                 system("CLS");
             }
     }
     while(nbr!=s);
     test(g);
     getch();
     printf("appuyez sur une touche pour quitter et revenir au menu");
}

